<?php

/**
 * This file is part of Webman AI.
 *
 * @author    walkor<walkor@workerman.net>
 * @copyright walkor<walkor@workerman.net>
 * @link      http://www.workerman.net/
 */

namespace plugin\ai\app\handler;

/**
 * 需要 dify2openai 的中转工具
 */
class Dify extends Base
{
    /**
     * @var string 模型处理器名称
     */
    protected static $name = 'Dify';

    /**
     * @var string 模型类型
     */
    protected static $type = 'dify';

    /**
     * @var string[] 支持的模型名称
     */
    public static $models = [];

    /**
     * @var string[] 自定义配置
     */
    public static $defaultSettings = [
        'apikey' => [
            'name' => 'ApiKey',
            'type' => 'text',
            'value' => '',
        ],
        'api' => [
            'name' => 'API',
            'type' => 'text',
            'value' => '',
        ],
        'userId' => [
            'name' => 'Dify用户ID',
            'type' => 'text',
            'value' => '',
        ],
        'regFreeCount' => [
            'name' => '注册赠送',
            'type' => 'number',
            'value' => 0,
        ],
        'dayFreeCount' => [
            'name' => '每日赠送',
            'type' => 'number',
            'value' => 0,
        ],
    ];

    /**
     * @var string 处理器
     */
    protected $driverClass = driver\Gpt::class;

    /**
     * 对话
     * @param $data
     * @param $options
     * @return void
     */
    public function completions($data, $options)
    {
        $settings = $this->getSettings();
        $this->driver = new $this->driverClass($settings);
        $data['user_id'] = $settings['userId'];
        $this->driver->completions($data, $options);
    }

}